package com.linkstec.wechat;

import java.util.HashMap;
//import java.util.concurrent.TimeUnit;
import java.util.concurrent.CountDownLatch;

import org.apache.commons.lang3.exception.ExceptionUtils;
import org.apache.http.entity.StringEntity;
import org.apache.http.impl.nio.client.CloseableHttpAsyncClient;

import com.linkstec.util.HttpAsyncClientUtil;

import lombok.extern.slf4j.Slf4j;

@Slf4j
public class BaiduVidpressService {

    static CloseableHttpAsyncClient client = null;
    static StringEntity entity = null;

    // 基础支持: 获取access_token接口 /token
    // https://aip.baidubce.com/oauth/2.0/token?grant_type=client_credentials&client_id=3x5E74KqNIbvTk9RqS71fflv&client_secret=7SvxofWDX46t6VXLkLN7WqWpezwj2qi9
    public static void main(String[] args) {

//        createVidpress();
        vidpressQueyr();

    }

    public static void createVidpress() {
        String url = "https://aip.baidubce.com/rpc/2.0/brain/vidpress/v1/create_vidpress?access_token=";
        String accessToken = "24.3e7c4f8b434e40fe73efe4da43ab0dc7.2592000.1692759020.282335-36102260";
        url = url + accessToken;
        HashMap<String, Object> map = new HashMap<String, Object>();
        map.put("newsUrl", "http://www.linkstec.com/info.php?mod=detail&id=199");
        map.put("ttsPer", 103);
        map.put("duration", 60);
        map.put("resolution", "1280x720");
        CountDownLatch countDownLatch = new CountDownLatch(1);
        HttpAsyncClientUtil.getClient();
        HttpAsyncClientUtil.startHttpAsyncClient();
        HttpAsyncClientUtil.post(url, map, countDownLatch);
        try {
            countDownLatch.await();
        } catch (InterruptedException e) {
            log.error(ExceptionUtils.getStackTrace(e));
        } finally {
            HttpAsyncClientUtil.closeHttpAsyncClient();
        }
    }
    public static void vidpressQueyr() {
        String url = "https://aip.baidubce.com/rpc/2.0/brain/vidpress/v1/query?access_token=";
        String accessToken = "24.3e7c4f8b434e40fe73efe4da43ab0dc7.2592000.1692759020.282335-36102260";
        url = url + accessToken;
        HttpAsyncClientUtil.getClient();
        HttpAsyncClientUtil.startHttpAsyncClient();
        HashMap<String, Object> map = new HashMap<String, Object>();
        map.put("jobId", 127587);
        CountDownLatch countDownLatch = new CountDownLatch(1);
        HttpAsyncClientUtil.post(url, map, countDownLatch);
        try {
            countDownLatch.await();
        } catch (InterruptedException e) {
            log.error("",  e);
        } finally {
            HttpAsyncClientUtil.closeHttpAsyncClient();
        }
    }


}